#!/bin/bash

# refer to https://gitee.com/api/v5/oauth_doc#/list-item-2
token_file=~/.gitee_token.json
source ~/.gitee_secret
if [ -e $token_file ]; then
    chmod 600 $token_file
fi
echo "Refreshing ~/.gitee_token.json"
curl -s -X POST --data-urlencode "grant_type=password" --data-urlencode "username=$username" --data-urlencode "password=$password" --data-urlencode "client_id=$client_id" --data-urlencode "client_secret=$client_secret" --data-urlencode "scope=projects pull_requests issues notes" https://gitee.com/oauth/token > $token_file
chmod 400 $token_file
